package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.TestResultsDao;
import com.exigen.perflabstat.models.TestResults;


public class TestResultsJpaDao extends GenericJPADAO<TestResults, Long> implements TestResultsDao  {
	
	public TestResultsJpaDao() {
		super(TestResults.class);
	}

	@SuppressWarnings("unchecked")
	public List<TestResults> allTestResults() {
		
		Query query = getEntityManager().createQuery("from TestResults");
		
		List<TestResults> result = query.getResultList();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TestResults checkIfExists(TestResults testResults) {

		TestResults testResults1 = null;
		
		Query query = getEntityManager().createQuery("select testResults from TestResults testResults where testResults.TRANSACTION_ID = :transactionId and testResults.TESTSUMMARY_ID = :testSummaryId");
		query.setParameter("transactionId", testResults.getTRANSACTION_ID());
		query.setParameter("testSummaryId", testResults.getTESTSUMMARY_ID());
		query.setMaxResults(1);
		
		List<TestResults> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		testResults1 = result.get(0);
		
		return testResults1;
	}

}
